My Shell
CS 345 - Project One


Purpose

A shell (also called a Command Language Interpreter) is an interface to an Operating System. A shell is a software module that interprets textual commands coming either from the user’s keyboard or from a script file and executes the commands either directly or creates a new child process to execute the command. Signal processing is generally at the shell level. Usually, a shell will provide command history and interactive name completion mechanisms.


Project Description

For Project 1, you are to write a shell task for your operating system. Your shell should prompt the user for keyboard input. After a sequence of characters is entered followed by a return, the string is parsed and the indicated command executed, either directly or as a background task.

The following are important guidelines for the shell exercise:

  1. Create a new project in your IDE. Download and add the following files to your OS project (by right clicking and choosing "Save Target As..."):

    Edit os345.h (if necessary) to select host OS/IDE/ISA. (Only enable one of the following defines: DOS, GCC, MAC, or NET.)

  2. Your shell should be written in C and as a task (P1_shellTask) scheduled from your operating system (os345.c). (Shell commands are C functions.)
  3. All commands and parameters should come from the keyboard inbuffer string or from a script file (Project 6) and parsed into traditional C argc and malloc'd argv variables.
  4. Your shell must support background execution of command programs. An ampersand (&) at the end of the command line indicates to the shell that the command is to be executed by a newly created, background task. The command arguments are passed to the new task in the malloc'd argv strings for execution. After creating the new task, the shell then recovers malloc'd memory and immediately prompts for the next command. Otherwise, your shell executes the command directly with a function call, waiting for the function to return before recovering memory and reprompting for the next command.
  5. To simulate character interrupts, keyboard character inputs are to be polled (pollInterrupts) during the scheduling loop. (SWAP macros should be liberally placed throughout your user code to ensure timely execution of your polling routine - DO NOT put SWAP's in system code).)
  6. Command parameters are strings, quoted strings ("This is one argument"), decimal numbers, or hexadecimal numbers (ie. 0xa19f).
  7. Other than the few required commands, you are to decide the look and feel (syntax and semantics) as well as which commands to implement. You may define command and argument delimiters, but you must address case sensitivity issues. (Is "LS" the same as "ls" or "Ls"?) Commands may be terse and/or verbose (ie, ls and list).
  8. Some extended form of a help command is required.
  9. Before a process is scheduled, any pending signals must be properly handled as explained below.
  10. Make your shell scalable as you will be adding additional functionality in subsequent projects.


Signals

A signal is a limited form of inter-process communication used in Unix, Unix-like, and other POSIX-compliant operating systems. Essentially, a signal is an asynchronous notification of an event that is sent to a process before it is rescheduled for execution.

When a signal is sent to a process, the operating system interrupts the process' normal flow of execution (when it is scheduled) and executes a signal handler. If the process has previously registered a signal handler, that routine is executed. Otherwise the default signal handler is executed. Execution can be interrupted during any non-atomic instruction.

Blocked processes are not un-blocked by a signal, but rather the signal remains pending until such time as the process is un-blocked and scheduled for execution.

The following table is summarizes how signals might be handled by your operating system:

Signal PollInterrupts Scheduler Dispatcher Signal Handler
SIGCONT Cntrl-R
sigSignal(-1, SIGCONT);
(Clear SIGSTOP
and SIGTSTP in all tasks)
n.a. Clear SIGCONT
Call sigContHandler()
Schedule task
return;
SIGINT Cntrl-X
sigSignal(0, SIGINT);
semSignal(inBufferReady);
n.a. Clear SIGINT
Call sigIntHandler()
Schedule task
sigSignal(-1, SIGTERM);
SIGTERM n.a. n.a. Clear SIGTERM
Call sigTermHandler()
Do not schedule task
killTask(curTask);
(Note: killTask does not
terminate shell)
SIGTSTP Cntrl-W
sigSignal(-1, SIGTSTP);
n.a. Clear SIGTSTP
Call sigTstpHandler()
Do not schedule task
sigSignal(-1, SIGSTOP);
SIGSTOP n.a. TASK NOT
SCHEDULED
n.a. No handler needed

Handling Control Signals

Certain combinations of characters entered at the controlling terminal of a running process cause the system to signal the process. Signals are processed just before a process is scheduled for execution. For project 1, the following control character signals are to be handled:

Signal handlers can be installed with the sigAction() system call. If a signal handler is not installed for a particular signal, the default handler is used.


Programming Environments

The choice of the software tools and programming environment is your choice. The C programming language will be used for all programming assignments and is available as follows:


Grading and Pass-off

Your Shell is to be demonstrated in person to a TA as follows:

  1. Your Shell task should parse the command line arguments into traditional argc and argv C variables. Use malloc to allocate space for argv and the string arguments. Recover the allocated space with the free function when a task/function terminates/returns. argc is the number of command line arguments. argv is a pointer to an array of pointers that point to the character string arguments. argv[0] is the first parameter (the command), so argc will always be at least 1.
  2. Implement the following shell commands:
  3. Implement background execution of programs. If the command line ends with an ampersand (&), your shell should create a new task to execute the command line. Otherwise, your shell should directly call the command function (and wait for the function to return.) Use the createTask function to create a background process.
  4. Add signal functionality to your shell such that:
  5. Implement additional functionality to your Shell such as:
  6. There are 20 points possible for Project 1. The grading criteria will be as follows:
  7. In addition, after completing the above requirements, the following bonus points may be awarded:

    NOTE: Bonus points may be received anytime during the semester (regardless of any late penalties) as long as all the project requirements have been completed.